package com.heima.wemedia;


import com.heima.file.service.FileStorageService;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;

import java.io.FileInputStream;
import java.io.FileNotFoundException;

@SpringBootTest
public class OssDemo {


    @Autowired
    private FileStorageService fileStorageService;


    @Value("${file.oss.prefix}")
    String prefix;

    @Value("${file.oss.web-site}")
    String webSite;

    /**+
     *  上传图片
     * @throws FileNotFoundException
     */
    @Test
    public void uploadPic() throws FileNotFoundException {

        FileInputStream fileInputStream = new FileInputStream("D:\\baidu\\picture\\002.jpg");
                                                //阿里云oss中目录名称  文件的名称
        //返回值：文件再oss中的完整名称
        String store = fileStorageService.store(prefix, "bz002.jpg", fileInputStream);

        System.out.println(webSite+store);
    }

    /**
     * 删除图片
     * @throws FileNotFoundException
     */
    @Test
    public void deletePic() throws FileNotFoundException {
        fileStorageService.delete("material/2022/7/20220704/bz002.jpg");
    }

}
